package com.aspose.cells;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

class zby {
   private MessageDigest g;
   private long h = 0L;
   private long i = 0L;
   private byte[] j;
   long a;
   long b;
   String c;
   private boolean k;
   private zjr l;
   byte[] d;
   byte[] e;
   byte[] f;

   public zby(String var1, byte[] var2, String var3, long var4, long var6, long var8, long var10, long var12) throws UnsupportedEncodingException {
      if (var1 != null && var1.length() != 0) {
         if (var1.length() > 15) {
            throw new IllegalArgumentException("The password can not be more than 15 characters.");
         } else {
            try {
               this.g = MessageDigest.getInstance("SHA-1");
            } catch (NoSuchAlgorithmException var15) {
               throw new RuntimeException(var15);
            }

            byte[] var14 = var1.getBytes("UTF-16LE");
            this.a = var4;
            this.b = var12;
            this.c = var3;
            this.d = var2;
            this.j = this.a(var14, var2);
            this.l = zjq.a(zcgd.b, zcgg.c);
            if (this.j == null) {
               throw new IllegalArgumentException("The container's parameter is wrong.");
            } else {
               if (!this.c.equals("Microsoft Base Cryptographic Provider v1.0") && !this.c.equals("Microsoft Base DSS and Diffie-Hellman Cryptographic Provider") && !this.c.equals("Microsoft DH SChannel Cryptographic Provider") && !this.c.equals("Microsoft Enhanced DSS and Diffie-Hellman Cryptographic Provider")) {
                  this.k = false;
               } else {
                  this.k = true;
               }

            }
         }
      } else {
         throw new IllegalArgumentException("The password could not be null or empty.");
      }
   }

   public static zby a(String var0, int var1, int var2) throws UnsupportedEncodingException {
      byte[] var3 = new byte[]{-3, 34, 93, -54, 1, 39, 59, -93, -92, -108, 96, -57, 85, 46, -12, 62};
      String var4 = "";
      switch(var1) {
      case 2:
         var4 = "Microsoft Enhanced Cryptographic Provider v1.0";
         break;
      case 3:
         var4 = "Microsoft Strong Cryptographic Provider";
      }

      zby var5 = new zby(var0, var3, var4, 1L, 0L, 32772L, 26625L, (long)var2);
      var5.d = new byte[]{-3, 34, 93, -54, 1, 39, 59, -93, -92, -108, 96, -57, 85, 46, -12, 62};
      var5.e = new byte[16];
      var5.f = new byte[20];
      var5.a(0L);
      zjq.b(var5.l, var3, 0, 16, var5.e, 0, 16);
      System.arraycopy(var5.a(var5.d), 0, var5.f, 0, 20);
      zjq.b(var5.l, var5.f, 0, 20, var5.f, 0, 20);
      return var5;
   }

   public byte[] a(byte[] var1, byte[] var2) {
      byte[] var3 = new byte[var1.length + var2.length];
      System.arraycopy(var2, 0, var3, 0, var2.length);
      System.arraycopy(var1, 0, var3, var2.length, var1.length);
      byte[] var4 = this.a(var3);
      return var4;
   }

   public boolean b(byte[] var1, byte[] var2) {
      byte var3 = 16;
      this.a(0L);
      zjq.a((zjr)this.l, var1, 0, var3, var1, 0, var3);
      byte[] var4 = new byte[20];
      var4 = this.a(var1);
      zjq.a((zjr)this.l, var2, 0, 20, var2, 0, 20);
      return (new String(var2)).equals(new String(var4));
   }

   public void a() {
      this.i = 0L;
      this.h = 0L;
   }

   public void a(long var1) {
      byte[] var3 = new byte[]{(byte)((int)(var1 & 255L)), (byte)((int)((var1 & 65280L) >> 8)), (byte)((int)((var1 & 16711680L) >> 16)), (byte)((int)((var1 & -16777216L) >> 24))};
      byte[] var4 = new byte[4 + this.j.length];
      System.arraycopy(this.j, 0, var4, 0, this.j.length);
      System.arraycopy(var3, 0, var4, this.j.length, 4);
      byte[] var5 = this.a(var4);
      byte[] var6 = new byte[20];
      System.arraycopy(var5, 0, var6, 0, (int)(this.b / 8L));
      if (this.k) {
         zjq.a(this.l, zcge.b, var6, (int)(this.b / 8L), (byte[])null, 0);
      } else {
         zjq.b(this.l, zcge.b, var6, (int)(this.b / 8L), (byte[])null, 0);
      }

   }

   public byte[] a(byte[] var1, long var2) {
      return this.a(var1, var1.length, var2);
   }

   private byte[] a(byte[] var1, int var2, long var3) {
      boolean var9 = false;
      int var16 = (int)(var3 - this.i);
      if (var3 % 1024L == (long)var16) {
         this.a(var3 >> 10);
      }

      byte[] var11;
      int var12;
      if ((long)var16 + this.i % 1024L > 1024L) {
         var11 = new byte[1024 - (int)(this.i % 1024L)];

         for(var12 = 0; var12 < var11.length; ++var12) {
            var11[var12] = -52;
         }

         var16 = var11.length;
         zjq.a((zjr)this.l, var11, 0, var11.length, var11, 0, var11.length);
         this.a(var3 >> 10);
         var11 = new byte[(int)(var3 % 1024L)];

         for(var12 = 0; var12 < var11.length; ++var12) {
            var11[var12] = -52;
         }

         var16 = var11.length;
         zjq.a((zjr)this.l, var11, 0, var11.length, var11, 0, var11.length);
      } else {
         var11 = new byte[var16];

         for(var12 = 0; var12 < var16; ++var12) {
            var11[var12] = -52;
         }

         zjq.a((zjr)this.l, var11, 0, var11.length, var11, 0, var11.length);
      }

      byte[] var10;
      int var17;
      if (var3 % 1024L + (long)var2 >= 1024L) {
         var17 = (int)(1024L - var3 % 1024L);
         var12 = var2 - var17;
         var10 = new byte[var17];
         byte[] var13 = new byte[var2];

         int var14;
         for(var14 = 0; var14 < var17; ++var14) {
            var10[var14] = var1[var14];
         }

         zjq.a((zjr)this.l, var10, 0, var10.length, var10, 0, var10.length);
         System.arraycopy(var10, 0, var13, 0, var17);

         for(long var7 = var3 + (long)var17; var12 > 0; var17 += var14) {
            this.a(var7 >> 10);
            var14 = var12 > 1024 ? 1024 : var12;
            var10 = new byte[var14];

            for(int var15 = 0; var15 < var14; ++var15) {
               var10[var15] = var1[var17 + var15];
            }

            zjq.a((zjr)this.l, var10, 0, var10.length, var10, 0, var10.length);
            System.arraycopy(var10, 0, var13, var17, var14);
            var12 -= var14;
            var7 += (long)var14;
         }

         this.i = var3 + (long)var2;
         return var13;
      } else if (var3 % 1024L + (long)var2 >= 1024L) {
         return null;
      } else {
         var10 = new byte[var2];

         for(var17 = 0; var17 < var2; ++var17) {
            var10[var17] = var1[var17];
         }

         if (var3 % 1024L == 0L) {
            this.a(var3 >> 10);
         }

         zjq.a((zjr)this.l, var10, 0, var10.length, var10, 0, var10.length);
         this.i = var3 + (long)var2;
         return var10;
      }
   }

   public byte[] b(byte[] var1, long var2) {
      return this.b(var1, var1.length, var2);
   }

   private byte[] b(byte[] var1, int var2, long var3) {
      boolean var9 = false;
      int var16 = (int)(var3 - this.h);
      if (var3 % 1024L == (long)var16) {
         this.a(var3 >> 10);
      }

      byte[] var11;
      int var12;
      if ((long)var16 + this.h % 1024L > 1024L) {
         var11 = new byte[1024 - (int)(this.h % 1024L)];

         for(var12 = 0; var12 < var11.length; ++var12) {
            var11[var12] = -52;
         }

         var16 = var11.length;
         zjq.a((zjr)this.l, var11, 0, var11.length, var11, 0, var11.length);
         this.a(var3 >> 10);
         var11 = new byte[(int)var3 % 1024];

         for(var12 = 0; var12 < var11.length; ++var12) {
            var11[var12] = -52;
         }

         var16 = var11.length;
         zjq.a((zjr)this.l, var11, 0, var11.length, var11, 0, var11.length);
      } else {
         var11 = new byte[var16];

         for(var12 = 0; var12 < var16; ++var12) {
            var11[var12] = -52;
         }

         zjq.a((zjr)this.l, var11, 0, var11.length, var11, 0, var11.length);
      }

      byte[] var10;
      int var17;
      if (var3 % 1024L + (long)var2 >= 1024L) {
         var17 = (int)(1024L - var3 % 1024L);
         var12 = var2 - var17;
         var10 = new byte[var17];
         byte[] var13 = new byte[var2];

         int var14;
         for(var14 = 0; var14 < var17; ++var14) {
            var10[var14] = var1[var14];
         }

         zjq.a((zjr)this.l, var10, 0, var10.length, var10, 0, var10.length);
         System.arraycopy(var10, 0, var13, 0, var17);

         for(long var7 = var3 + (long)var17; var12 > 0; var17 += var14) {
            this.a(var7 >> 10);
            var14 = var12 > 1024 ? 1024 : var12;
            var10 = new byte[var14];

            for(int var15 = 0; var15 < var14; ++var15) {
               var10[var15] = var1[var17 + var15];
            }

            zjq.a((zjr)this.l, var10, 0, var10.length, var10, 0, var10.length);
            System.arraycopy(var10, 0, var13, var17, var14);
            var12 -= var14;
            var7 += (long)var14;
         }

         this.h = var3 + (long)var2;
         return var13;
      } else if (var3 % 1024L + (long)var2 >= 1024L) {
         return null;
      } else {
         var10 = new byte[var2];

         for(var17 = 0; var17 < var2; ++var17) {
            var10[var17] = var1[var17];
         }

         if (var3 % 1024L == 0L) {
            this.a(var3 >> 10);
         }

         zjq.a((zjr)this.l, var10, 0, var10.length, var10, 0, var10.length);
         this.h = var3 + (long)var2;
         return var10;
      }
   }

   public byte[] c(byte[] var1, long var2) {
      this.a();
      this.a(var2);
      zjq.a((zjr)this.l, var1, 0, var1.length, var1, 0, var1.length);
      return var1;
   }

   private byte[] a(byte[] var1) {
      this.g.update(var1);
      return this.g.digest();
   }
}
